// Class to create an offer
public class Offer {
	
	private String trader;
	private int traderID;
	private Database.ORE oreName;
	private int oreQuantity;
	private String offerType;
	private int price;
	
	// Create an empty offer, could set some default values
	public Offer() {
		
	}
	
	// Create an offer and set the values
	public Offer(String _trader, int _traderID, Database.ORE _oreName, int _oreQuantity, String _offerType, int _price) {
		this.trader = _trader;
		this.traderID = _traderID;
		this.oreName = _oreName;
		this.oreQuantity = _oreQuantity;
		this.offerType = _offerType;
		this.price = _price;
	}
	
	// Returns true if the trader is in the database
	public boolean isTraderValid() {
		return ValidationController.db.containsTrader(this.trader);
	}
	
	// Returns true if the ore is in the database
	public boolean isOreNameValid() {
		return ValidationController.db.containsOre(this.oreName);
	}
	
	// Returns true if the ore quantity is positive
	public boolean isOreQuantityPositive() {
		if (oreQuantity > 0) {
			return true;
		}
		return false;
	}
	
	// Returns true if any one trader can afford this offer
	public boolean canAnyTraderAffordThis() {
		if ((this.oreQuantity * this.price) < ValidationController.db.maximumMoney()) {
			return true;
		}
		return false;
	}
	
	// Returns true if this trader can afford to make this offer
	public boolean canThisTraderAffordThis() {
		// check to see trader has more money than the cost of the sell offer
		if (ValidationController.db.getTrader(trader).fundsAvailable > (this.oreQuantity * this.price)) {
			// check to see if the trader has enough ore available
			if (this.oreQuantity > ValidationController.db.amountOfTradersOre(trader, oreName)) {
				return true;
			}
		}
		return false;
	}
	
	// Returns true if the price is greater or equal to zero
	public boolean isPriceGreaterOrEqualToZero() {
		return price >= 0;
	}
	
	//
	// Getters and setters
	//
	public String getTrader() {
		return trader;
	}
	
	public void setTrader(String trader) {
		this.trader = trader;
	}

	public int getTraderID() {
		return traderID;
	}

	public void setTraderID(int traderID) {
		this.traderID = traderID;
	}

	public Database.ORE getOreName() {
		return oreName;
	}

	public void setOreName(Database.ORE oreName) {
		this.oreName = oreName;
	}

	public int getOreQuantity() {
		return oreQuantity;
	}

	public void setOreQuantity(int oreQuantity) {
		this.oreQuantity = oreQuantity;
	}

	public String getOfferType() {
		return offerType;
	}

	public void setOfferType(String offerType) {
		this.offerType = offerType;
	}

	public int getPrice() {
		return price;
	}

	public void setPrice(int price) {
		this.price = price;
	}
}
